Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

21.2 Establishing the Clock Tick and Broadcast Framework

The clock tick serves as the definitive heartbeat of the Linux kernel. It is fundamentally a periodic hardware interrupt triggered consistently by a dedicated hardware timer. Without this clock tick rhythm, the kernel would operate like a clock stripped of its second hand—rendering it completely incapable of executing process scheduling or managing event timeout tasks.

Whenever a clock tick interrupt manifests, the kernel coordinates the following operations:

  • Increments the global jiffies counter, which tracks the aggregate count of clock ticks that have elapsed since system boot.

  • Audits whether the currently running process has exhausted its allocated execution time slice; if the budget is spent, it signals the core scheduler (CFS/EEVDF) to execute a context switch.

  • Evaluates whether any low-resolution timers managed within the Timer Wheel have reached their expiration boundaries.

  • Updates the localized CPU execution runtime accounting metrics tracking user-space versus kernel-space duration statistics.

The contemporary Linux kernel supports two primary operational clock tick modes: the Periodic Tick mode and the Dynamic Tick (NO_HZ / Tickless) mode.

  • Under the periodic tick paradigm, a hardware timer continuously broadcasts interrupts at a fixed frequency configured during compilation (such as 100 Hz, 250 Hz, or 1000 Hz). Under this constraint, even if a CPU core drops into a deep sleep state, it is forced to continuously wake up to process this background tick, which penalizes the system's power footprint.

  • The dynamic tick paradigm operates across two distinct modalities: idle and full. When the dynamic tick mechanism operates under the idle configuration, the moment a CPU core drops into an idle state, the kernel computes the exact expiration timeline of the next scheduled timer event and programs the hardware alarm to target that precise checkpoint; throughout the intermediate window, the periodic clock tick is completely suspended, enabling the processor core to maintain a deep, uninterrupted sleep state. In high-performance computing or hard real-time environments where reducing latency and processing overhead is paramount, if a specific CPU core is occupied by exactly one isolated executable task, the kernel can completely disable the clock tick on that core to eliminate interrupt pipeline interference; under this explicit condition, the dynamic tick mechanism operates under the full configuration.

The baseline synchronization structures governing the clock tick framework are established via the routine tick_init(). This function is implemented within the source file git/kernel/time/tick-common.c, and its definition is structured as follows:

void __init tick_init(void)
{
	tick_broadcast_init();
	tick_nohz_init();
}

Although this routine spans only two execution statements, it builds the top-level master architectural framework for contemporary Linux time management. It dictates whether the operating system behaves like a legacy alarm clock that continuously "ticks" without pause, or operates like a smartphone that remains asleep and awakens exclusively when a real-time task demands attention.

The sub-routine tick_broadcast_init() dynamic allocates memory for the tracking masks (bitmaps) consumed by the clock tick broadcast infrastructure and flushes the allocated memory blocks to zero. This setup initializes three foundational bitmaps: tick_broadcast_mask, tick_broadcast_on, and tmpmask. Within this framework, tick_broadcast_mask maps out the explicit subset of CPU cores that are registered to receive incoming wakeup clock tick signals. Furthermore, if the kernel image is compiled with single-shot tick support active via CONFIG_TICK_ONESHOT, the allocator dynamic carves out three additional tracking masks reserved for one-shot operational modes, within which tick_broadcast_oneshot_mask records the specific CPU cores whose clock ticks must be proxy-triggered by the global broadcast timer.

The introduction of the clock tick broadcast mechanism elegant resolves a critical multi-core hardware challenge. Across symmetric multiprocessing (SMP) systems, each individual CPU core typically incorporates a private, localized hardware timer. Whenever a CPU core drops into a deep, low-power sleep state, its private local timer is frequently forced to completely shut down. Under this constraint, if no external hardware stimulation disrupts the core, the processor would remain trapped in a perpetual sleep cycle, completely missing its pre-scheduled runtime tasks.

To eliminate this vulnerability, Linux relies on a globally accessible system timer—a specialized hardware component whose clock tracking logic is immune to CPU low-power sleep cycles. When a specific processor core prepares to enter a deep sleep state, it delegates its future wakeup responsibility to this global timer. The moment the programmed timeline elapses, the global timer fires a hardware interrupt, prompting an active processor core (typically CPU 0) to propagate an Inter-Processor Interrupt (IPI) across the system bus to forcefully awaken the sleeping CPU core. The execution of tick_broadcast_init() bootstraps this entire distributed broadcast framework.

Traditional Linux implementations strictly relied on periodic clock ticks; meaning that regardless of whether the processor faced active workloads or sat completely idle, the CPU core was constantly interrupted multiple times per second (governed by the constant HZ, configured at compile time to map to values like 100 or 1000). If a CPU core remained idle over extended windows, this persistent, high-frequency interrupt processing severely penalized energy efficiency. To optimize this path, modern kernels introduce tickless or dynamic clock modes. By configuring the compilation choices CONFIG_HZ_PERIODIC (traditional periodic mode), CONFIG_NO_HZ_IDLE (dynamic clock idle mode), and CONFIG_NO_HZ_FULL (adaptive full dynamic clock mode), users can select the execution behavior best suited to their deployment target. Under the periodic mode, the clock tick never stops. Under the dynamic clock idle mode, the moment a CPU core drops into an idle status, the periodic clock interrupt is completely halted. Under the full dynamic mode, the kernel attempts to disable or heavily throttle the scheduling clock tick not only during idle states but also when a CPU core executes exactly one isolated runnable task. The full dynamic clock tick mode is predominantly deployed within low-latency, hard real-time systems.

The routine tick_nohz_init() executes the baseline initialization steps for the tickless operational infrastructure, marking a critical milestone in the evolution of the Linux kernel toward extreme power optimization and high-performance computing. This function initializes the internal subsystem state machines and configures the corresponding static keys bitmask flags based on the active kernel compilation definitions (such as CONFIG_NO_HZ_COMMON) and boot parameters (such as nohz=on). The function tick_nohz_init() is hosted within the source file git/kernel/time/tick-sched.c, and its definition is implemented as follows:

The tick_nohz_init() function initializes the full dynamic tick (NO_HZ_FULL) orchestration framework.

It first checks the state of the tick_nohz_full_running flag and queries whether the underlying processor architecture supports hardware-triggered, self-directed Inter-Processor Interrupts (self-IPIs) via arch_irq_work_has_interrupt(). If the system is a symmetric multiprocessing (SMP) platform with hibernation capabilities enabled (CONFIG_PM_SLEEP_SMP), but it strictly prohibits or lacks support for offlining non-boot cores via hotplug operations during power transitions (!CONFIG_PM_SLEEP_SMP_NONZERO_CPU), the current execution core is checked against the full dynticks mask. If a match is found, the kernel clears this core from the tick_nohz_full_mask range to safeguard the system's global timekeeping operations, printing a warning diagnostic.

The subsequent code blocks iterate across the tick_nohz_full_mask bitmask (which registers which explicit CPU cores are authorized to deactivate their periodic clock tick interrupts). It systematically loops through all processor cores specified for full dynamic dynticks execution via boot command-line arguments (such as nohz_full=1-3), executing context tracking initialization and registering the dynamic CPU hotplug callbacks. Because a core that disables its periodic clock tick must still maintain precise tracking of its active execution context (USER, KERNEL, or IDLE) to safely support the RCU state machine and tickless tracking subsystems, context tracking must be dynamically energized. Activating this tracking framework via context_tracking_cpu_set() represents a strict microarchitectural prerequisite for the stable execution of the NO_HZ_FULL mechanism.

The function cpuhp_setup_state_nocalls() allocates a dynamic hotplug tracking slot within the kernel's CPU hotplug framework under the index CPUHP_AP_ONLINE_DYN. It labels this step as "kernel/nohz:predown", sets the online startup callback argument to NULL, and registers the teardown callback target to point to tick_nohz_cpu_down. In this configuration, only the teardown callback tick_nohz_cpu_down is populated, ensuring that appropriate cleanup routines are executed whenever a dynamic dynticks core is designated to drop offline. The _nocalls suffix dictates that the hotplug infrastructure will not instantly invoke this callback against the cores currently online in the system, deferring execution exclusively for future real-time hotplug transitions.

In essence, the loop module at the conclusion of the routine executes a vital boot milestone: it registers specific CPU cores to transition into full dynamic tick operations and guarantees that if any of these targeted cores are taken offline via hotplug sequences, the system can gracefully wind down and clean up their isolated local timer logic.

The physical execution carrier of the clock tick rhythm is the Clock Event Device (struct clock_event_device). Following early initialization, the time subsystem selects the highest-precision hardware device available on the platform (such as the ARM Generic Timer or the x86 LAPIC Timer) to serve as the physical foundation for the clock tick. Following this configuration, the kernel programs the hardware timer via set_next_event(), passing down the technical instruction: "assert a hardware interrupt precisely after $X$ nanoseconds."

The standard operational call path of the clock tick subsystem within the kernel follows this processing pipeline:

  1. The low-level hardware timer reaches its programmed expiration boundary and asserts a physical interrupt line.

  2. The architecture layer catches the exception and routes execution to the primary flow handler, such as tick_handle_periodic().

  3. The flow routine dispatches do_timer() to execute atomic increments on the global system jiffies counter.

  4. The system invokes update_process_times() to refresh process scheduling analytics and raises the TIMER_SOFTIRQ vector.

This specific execution layout underscores exactly why the softirq_init() sequence must be completed and ready before the core components of the time subsystem are authorized to fully spin up.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com